feat - added vendor agnostic sonar backend#45
Open
Prathmesh2931 wants to merge 3 commits intoIOES-Lab:ros2from
Open
feat - added vendor agnostic sonar backend#45Prathmesh2931 wants to merge 3 commits intoIOES-Lab:ros2from
Prathmesh2931 wants to merge 3 commits intoIOES-Lab:ros2from
Conversation
Signed-off-by: Prathmesh Atkale <atkaleprathmesh@gmail.com>
…n fallback logic clean - unnecessary comment in CMakeList.txt Signed-off-by: Prathmesh Atkale <atkaleprathmesh@gmail.com>
6e8387a to
f3ff986
Compare
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Basic Info
Description of contribution in a few bullet points
sonar_compute_wgpu.hhdefining aSonarComputeBackendabstract interface andWgpuComputeBackendimplementation — the sensor can swap between CUDA, wgpu, and CPU backends at runtime via an SDF<compute_backend>parameter without recompilingsonar_compute_wgpu.ccimplementing the wgpu backend through a Rust static library over a stable C FFI boundary — GPU init failures fall back to CPU automatically without crashing the sensorwgpu_backend/— a Rust crate with three WGSL compute shaders implementing Choi et al. (2021) Algorithm 1, plus acbindgen-generated C header that stays in sync with the Rust source automaticallyCMakeLists.txtto optionally invokecargo build --releasewhen cargo is present — if cargo is absent the existing CUDA build is completely unaffectedsonar_calculation_cuda.cuand the CUDA path are untouchedDescription of the physics pipeline
Three WGSL compute shaders implement Choi et al. (2021) Algorithm 1:
backscatter.wgsl— Eq. 14 (scatter amplitude per ray) + Eq. 8 (coherent phase summation across frequency bins). Uses fixed-pointatomicAddfor parallel ray accumulation since WGSL has no native float atomics. Philox4x32-10 RNG (Salmon et al. 2011, same constants as CUDA curand) + Box-Muller transform generates the complex Gaussian speckle(ξ_xi + i·ξ_yi)/√2per raymatmul.wgsl— tiled 16×16 shared-memory GEMM for beam pattern correctionW·P/sum(W), replacing cuBLAS SGEMMfft.wgsl— Cooley-Tukey radix-2 FFT converting beam spectrumP_j(f)to time-domain echop_j(t). Range maps asr = t·c/(2B)wgpu selects Vulkan on Linux, Metal on macOS, and DirectX 12 on Windows — the same WGSL shaders run unchanged on any backend.
Description of how this change was tested
Validated on a standalone physics pipeline using the Blueview P900-90 sonar configuration from Choi et al. (2021) Table 1 (512 beams, 114 rays, 512 freq bins, B=2.95 kHz):
The peak bin check validates the full pipeline end-to-end: scatter amplitude (Eq. 14) → phase sweep (Eq. 8) → FFT → range. A flat floor at 10 m must produce a peak at bin
t = 10 × 2B/c = 39. Getting diff=0 confirms the frequency grid convention, phase accumulation, and FFT output indexing are all correct.Rust crate builds clean with
cargo build --releaseon Ubuntu 22.04.Description of documentation updates required
No documentation updates at this stage. Usage notes for the
<compute_backend>SDF parameter will be added once the hookup intoMultibeamSonarSensor.ccis reviewed and merged.Known limitations and follow-up work
MultibeamSonarSensor.ccis not yet wired to call the new backend — intentionally left for a follow-up PR once this interface is reviewed by maintainersn_freq;rustfftcrate integration for arbitrary sizes is planned as a follow-upD(θ,φ)beam pattern andS(f)source spectrum are set to 1 in this PR (ideal beam, flat spectrum) — full values are applied through the matmul pass in a follow-upMultibeamSonarSensor.ccintegration not tested on Gazebo Harmonic locally (Ubuntu 22.04 constraint) — CI will validate on the target platform